var ItemMenuItemRender = new Class({
	"Extends":js.underas.controller.ListViewItemRender
	,"initialize":function(p_obj){						
		var htmlTmp = '<h4><span class="glyphicon glyphicon-'+p_obj.icone+'"></span>'+p_obj.label+'</h4>';
		htmlTmp += '<p class="list-group-item-text">FUNCAO:'+p_obj.funcao+'</p>'; 
		//htmlTmp += '<p class="list-group-item-text">TELA:'+p_obj.tela+'</p>';
		htmlTmp += '<p class="list-group-item-text">ICONE:'+p_obj.icone+'</p>'; 
		this.parent('div',htmlTmp);
		this.getEle().addClass("col-xs-12 col-sm-6 col-md-6");
		}
	});

var ItemMenu = new Class({
	"Extends":js.underas.container.ModWindow
	,"itIdItemMenu":null	 
	,"itLabel":null	 
	,"itFuncao":null	 
	,"itTela":null 
	,"itIcone":null	
	,"itOrdem":null	
	,"initialize":function(){
		this.parent("*Itens do menu.");
		this.setRevision("$Revision: 143 $");		
		this.setSize(4);
		this.itIdItemMenu = new js.underas.controller.InputText("");
		this.itIdItemMenu.setColumn("$_id");
		this.itIdItemMenu.setLabel("cod.");
		this.itIdItemMenu.setEnable(false);	
		this.itIdItemMenu.setSize(4);	
		this.append(this.itIdItemMenu);	

		this.itLabel = new js.underas.controller.InputText("");
		this.itLabel.setColumn("@label");
		this.itLabel.setLabel("label");
		this.itLabel.setSize(8);	
		this.append(this.itLabel);

		this.itFuncao = new js.underas.controller.InputText("");
		this.itFuncao.setColumn("#funcao");
		this.itFuncao.setLabel("funcao");
		this.itFuncao.setSize(12);
		this.append(this.itFuncao);	

		this.itTela = new js.underas.controller.Select("selecione uma tela");
		this.itTela.setLabel("tela");
		this.itTela.setColumn("@tela");
		this.itTela.setSize(12);
		this.itTela.setValueField("modulo");
		this.itTela.setLabelField("descricao");
		this.append(this.itTela);

		this.itIcone = new js.underas.controller.Select("selecione um icone");
		this.itIcone.setLabel("icone");
		this.itIcone.setColumn("@icone");
		this.itIcone.setSize(8);
		this.itIcone.setValueField("icon");
		this.itIcone.setLabelField("desc");
		this.append(this.itIcone);
		
		this.itOrdem = new js.underas.controller.NumericStepper(5);
		this.itOrdem.setEnable(false,2);
		this.itOrdem.setSize(4);
		this.itOrdem.setLabel("ordem");
		this.itOrdem.setMin(1);
		this.itOrdem.setMax(100);
		this.itOrdem.setStep(1);
		this.itOrdem.setColumn("@ordem");
		this.append(this.itOrdem);
		
		this.mainList = new js.underas.controller.ListView("ItemMenu");
		this.mainList.setItemRender("ItemMenuItemRender");
		this.mainTb = new js.underas.net.ToolBar({"domain":"perfil/menu/menuitem"});

		this.append(this.mainTb);		
		this.append(this.mainList);
	}
	,"onStart":function(){
		this.itIcone.fromService("assets/icons.json");	
		this.itTela.fromService("assets/modulo.json");	
	}
	,"beforeInsert":function(p_obj){
		p_obj["url"]="perfil/menu/menuitem/"+perfil.itIdPerfil.getValue()+","+ menu.itIdMenu.getValue();
		//p_obj["method"]="post";
		//menu.getMainList().getSelectedItem().children[p_old_obj._ind] = p_req.data;
		return p_obj;
	}
	,"beforeUpdate":function(p_req,p_old_obj){
		//p_req["url"]="perfil/menu/menuitem/"+perfil.itIdPerfil.getValue()+","+ menu.itIdMenu.getValue();
		//p_req["method"]="put";
		//return p_new_obj;
		if(menu.getMainList().getSelectedItem().children){

		};
		menu.getMainList().getSelectedItem().children[p_old_obj._ind] = p_req.data;
		menu.mainTb.saveItem(null);
		return null;
	}
	,"beforeDelete":function(p_new_obj,p_old_obj){
		p_new_obj["url"]="perfil/menu/menuitem/"+perfil.itIdPerfil.getValue()+","+ menu.itIdMenu.getValue()+"," + p_old_obj._id;
		//p_new_obj["method"]="delete";
		return p_new_obj;
	}
});